﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;
using PollSystemDAL;

namespace PollSystemService
{
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface name "IService1" in both code and config file together.
    [ServiceContract]
    public interface IPollSystemService
    {
        [OperationContract]
        [WebInvoke(Method = "GET", UriTemplate = "Questions")]
        QuestionDTO[] GetQuestions();

        [OperationContract]
        [WebInvoke(Method = "GET", UriTemplate = "Answers")]
        AnswerDTO[] GetAnswers();

        [OperationContract]
        [WebInvoke(Method = "GET", UriTemplate = "Answers/{questionId}")]
        AnswerDTO[] GetAnswersByQuestionId(string questionId);

        [OperationContract]
        [WebInvoke(Method = "POST", UriTemplate = "VoteForAnswer/{answerId}")]
        void VoteForAnswer(string answerId);

        [OperationContract]
        [WebInvoke(Method = "POST", UriTemplate = "VoteForAnswerAndGetVotesCount/{answerId}")]
        AnswerDTO[] VoteForAnswerAndGetVotesCount(string answerId);

    }
            
    public class QuestionDTO
    {    
        public int QuestionId;    
        public string QuestionContent;

        public void Constructor(Question question)
        {
            this.QuestionId = question.QuestionId;
            this.QuestionContent = question.QuestionContent;
        }
    }
    
    public class AnswerDTO
    {        
        public int AnswerId;        
        public int QuestionId;        
        public string AnswerContent;
        public int VotesCount;

        public void Constructor(Answer answer)
        {
            this.AnswerId = answer.AnswerId;
            this.QuestionId = answer.QuestionId;
            this.AnswerContent = answer.AnswerContent;
            this.VotesCount = answer.VotesCount;
        }
    }

}
